package cn.edu.xbu.servlet;

import java.io.IOException;
import java.io.PrintWriter;

import javax.servlet.Servlet;
import javax.servlet.ServletConfig;
import javax.servlet.ServletException;
import javax.servlet.ServletRequest;
import javax.servlet.ServletResponse;
import javax.servlet.annotation.WebServlet;
//@WebServlet("/sign/out")等同於 @WebServlet(value="/sign/out")
//注解WebServlet的urlPatterns屬性與value屬性作用相同，都用來映射路徑
@WebServlet(urlPatterns="/sign/out" ,name="signOutServlet")
public class SingelServlet2 implements Servlet{

	private ServletConfig config;
	
	@Override
	//Servlet 容器（也就是Tomcat）通过初始化方法 向Servlet实例传递
			//请注意，Servlet容器 通过一个ServletConfig对象向servlet实例传递数据
	public void init(ServletConfig config) throws ServletException {
		System.out.println("初始化"+this);
		this.config=config;
	}
	
	@Override
	public void destroy() {
		System.out.println(this+"销毁");
		
	}
	
	@Override
	public ServletConfig getServletConfig() {
		return null;
	}

	@Override
	public String getServletInfo() {
		//直接返回config中关于当前Servlet实例的名称
		return config.getServletName();
	}
	
	@Override
	public void service(ServletRequest req, ServletResponse resp) throws ServletException, IOException {
		System.out.println(config.getServletName()+"提供服务("+this+")");
		System.out.println();
		
		
		PrintWriter out=resp.getWriter();
		out.println("<div style='text-lign:center;border:1px solid blue;padding:10px;>'");
		out.println("<h1>"+this+"</h1>");
		out.println("</div>");
		
	}
}
